package lovo.practice_7_14;

import lovo.Util.Util;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class SetPwdPanel extends JPanel implements ActionListener {
    private J189_7_14 frame;
    private JButton jButtonSetPwd;
    private JTextField jTextFieldNewPwd;
    private JButton jButtonBack;
    private Icon imgback = Util.getimagesIcon("/Images/buttonOff.jpg");

    public SetPwdPanel(J189_7_14 frame) {
        this.frame = frame;
        this.setLayout(null);
        this.setOpaque(false);

        jButtonSetPwd = new JButton("修改");
        jButtonSetPwd.setBounds(200, 200, 140, 50);
        this.add(jButtonSetPwd);

        jTextFieldNewPwd = new JTextField();
        jTextFieldNewPwd.setBounds(400, 200, 140, 50);
        this.add(jTextFieldNewPwd);
        jButtonBack = new JButton(imgback);
        jButtonBack.setBounds(600, 600, 140, 50);
        this.add(jButtonBack);
        jButtonBack.addActionListener(this);
        jButtonSetPwd.addActionListener(this);
//        jTextFieldNewPwd.addActionListener(this);
    }


    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == jButtonSetPwd) {
            frame.getUsers().setPwd(jTextFieldNewPwd.getText());
            JOptionPane.showMessageDialog(this, "修改成功");
        } else if (e.getSource() == jButtonBack) {
            frame.switchPanel("mune");
        }
    }
}
